package com.wandian.news.mvvm.fragmentlifetool;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMFragment;
import com.mylib.libcore.tools.CSJADTools;
import com.mylib.libcore.tools.GDTADTools;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.adapter.LifeToolRecycleAdapter;
import com.wandian.news.databinding.NewsLifeToolFragmentBinding;

import me.jessyan.autosize.utils.ScreenUtils;

import static com.mylib.libcore.config.AppConfig.CSJ_BANNER_ONE_ID;
import static com.mylib.libcore.config.AppConfig.GDT_APP_MB_PIC_TWO;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description LifeToolFragment
 **/
@Route(path = RouterConfig.ROUTER_FRAGMENT_NEWS_LIFE_TOOL)
public class LifeToolFragment extends BaseMVVMFragment<LifeToolFragmentViewModel> {
    private NewsLifeToolFragmentBinding dataBinding;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.inflate(inflater, R.layout.news_life_tool_fragment, container, false);
        return dataBinding.getRoot();
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        dataBinding.setViewModel(mViewModel);
        LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) dataBinding.viewSys.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
        linearParams.height = ScreenUtils.getStatusBarHeight();
        dataBinding.viewSys.setLayoutParams(linearParams);
        initViewData();
        initClink();
    }



    private void initViewData(){
        mViewModel.getDataJQ();
        mViewModel.getDataXTS();
        mViewModel.textJQ.observe(this,text->{
            if(!UIUtils.isEmpty(text))dataBinding.tvLifeJq.setText(text+"");
        });
        mViewModel.textXTS.observe(this,text->{
            if(!UIUtils.isEmpty(text))dataBinding.tvLifeXts.setText(text+"");
        });
        //获取广告
        CSJADTools.loadCSJAdMiddleBanner(getContext(),dataBinding.rlAdBottom,"",CSJ_BANNER_ONE_ID,375,120);
        GDTADTools.loadHFAdByID(getContext(),dataBinding.flAdBottom,GDT_APP_MB_PIC_TWO,375,0 );
    }

    private void initClink(){
        dataBinding.tvItemCpbd.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_MENU).navigation());
        dataBinding.tvItemSccf.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_FOOD).navigation());
        dataBinding.tvItemTzcx.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_BODY).navigation());
        dataBinding.tvItemZydq.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_MEDICINE).withString("title","中药大全").navigation());
        dataBinding.tvItemYwsm.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_MEDICINE).withString("title","药物说明").navigation());
        dataBinding.tvItemSrxg.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_BIRTH_DAY).navigation());
        dataBinding.tvItemXzys.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_CONSTELLATION).navigation());
        dataBinding.tvItemHlcx.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_NL).navigation());
        dataBinding.tvItemZgjm.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_ZGJM).navigation());
        dataBinding.tvItemLsjt.setOnClickListener(v ->  ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_HISTORY_TODAY).navigation());
    }


}
